package com.aosai.localtax.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;

import com.aosai.localtax.R;
import com.aosai.localtax.adapter.ViewPagerAdapter;
import com.aosai.localtax.app.BaseActivity;
import com.aosai.localtax.dao.TaskDao;
import com.aosai.localtax.model.MainViewPagerModel;
import com.squareup.okhttp.Response;

import java.util.List;

import cn.trinea.android.view.autoscrollviewpager.AutoScrollViewPager;
import me.relex.circleindicator.CircleIndicator;
import pw.hais.http.base.OnHttpListener;
import pw.hais.utils.L;

/**
 * Created by hais1992 on 2016/1/16/016.
 */
public class MainActivity extends BaseActivity implements View.OnClickListener {
    private ImageView image_btn_1, image_btn_2, image_btn_3, image_btn_4, image_btn_5, image_btn_6;
    private AutoScrollViewPager view_pager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        getSupportActionBar().hide();

        initViewAndLayout();
        getHttpDataAndShow();
    }

    private void initViewAndLayout() {
        view_pager = (AutoScrollViewPager) findViewById(R.id.view_pager);

        image_btn_1 = (ImageView) findViewById(R.id.image_btn_1);
        image_btn_2 = (ImageView) findViewById(R.id.image_btn_2);
        image_btn_3 = (ImageView) findViewById(R.id.image_btn_3);
        image_btn_4 = (ImageView) findViewById(R.id.image_btn_4);
        image_btn_5 = (ImageView) findViewById(R.id.image_btn_5);
        image_btn_6 = (ImageView) findViewById(R.id.image_btn_6);

        image_btn_1.setOnClickListener(this);
        image_btn_2.setOnClickListener(this);
        image_btn_3.setOnClickListener(this);
        image_btn_4.setOnClickListener(this);
        image_btn_5.setOnClickListener(this);
        image_btn_6.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.image_btn_4:
                Intent intent1 = new Intent(context,WebViewActivity.class);
                intent1.putExtra(WebViewActivity.INTENT_URL,"http://113.12.192.120:9006");
                intent1.putExtra(WebViewActivity.INTENT_TITLE,"大厅实时排队情况");
                startActivity(intent1);
                break;
            case R.id.image_btn_2:
                L.showShort("开发中...");
                break;
            case R.id.image_btn_3:
                Intent intent2 = new Intent(context,WebViewActivity.class);
                intent2.putExtra(WebViewActivity.INTENT_URL,"http://112.74.208.150:8989/taxGis/TaxGisServlet");
                intent2.putExtra(WebViewActivity.INTENT_TITLE,"办税地图");
                startActivity(intent2);
                break;
            case R.id.image_btn_1:
                L.showShort("开发中...");
                break;
            case R.id.image_btn_5:
                L.showShort("开发中...");
                break;
            case R.id.image_btn_6:
                L.showShort("开发中...");
                break;
        }
    }

    public void getHttpDataAndShow() {
        TaskDao.getList(new OnHttpListener<List<MainViewPagerModel>>() {
            @Override
            public void onSuccess(Response response, final List<MainViewPagerModel> data) {
                view_pager.setAdapter(new ViewPagerAdapter(context, data, MainActivity.this));
                view_pager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
                    @Override
                    public void onPageSelected(int position) {
                        super.onPageSelected(position);
                    }
                });

                view_pager.setInterval(2000);
                view_pager.startAutoScroll();

                CircleIndicator indicator = (CircleIndicator) findViewById(R.id.indicator_default);
                indicator.setViewPager(view_pager);
            }
        });
    }
}
